# Contributor: Alex Denes <caskd@redxen.eu>
# Maintainer: Alex Denes <caskd@redxen.eu>
pkgname=gperftools
pkgver=2.10.80
pkgrel=1
pkgdesc="Fast, multi-threaded malloc and nifty performance analysis tools"
url="https://github.com/gperftools/gperftools"
# everything else fails even more tests or isn't supported
arch="x86_64"
license="BSD-3-Clause"
makedepends="
	autoconf
	automake
	libtool
	libunwind-dev
	linux-headers
	"
subpackages="
	$pkgname-dev
	$pkgname-doc
	tcmalloc
	tcmalloc-minimal:tcmalloc_minimal
	tcmalloc-debug:tcmalloc_debug
	tcmalloc-minimal-debug:tcmalloc_minimal_debug
	tcmalloc-profiler:tcmalloc_profiler
	"
checkdepends="
	curl
	"
builddir="$srcdir/gperftools-gperftools-$pkgver"
source="https://github.com/gperftools/gperftools/archive/refs/tags/gperftools-$pkgver.tar.gz
	failed-tests.patch
	pkgconfig.patch
	"

prepare() {
	default_prepare

	autoreconf -fvi
}

build() {
	case "$CARCH" in
	x86_64)
		local frame_pointers="--enable-frame-pointers"
		;;
	esac

	./configure \
		--prefix=/usr \
		--build=$CBUILD \
		--host=$CHOST \
		--enable-libunwind \
		$frame_pointers

	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
}

pprof() {
	pkgdesc="$pkgdesc (pprof tools)"
	depends="perl"

	amove usr/bin/pprof*
}

tcmalloc() {
	pkgdesc="$pkgdesc (tcmalloc, full variant)"

	amove usr/lib/libtcmalloc.so.*
}

tcmalloc_debug() {
	pkgdesc="$pkgdesc (tcmalloc, debug variant)"

	amove usr/lib/libtcmalloc_debug.so.*
}

tcmalloc_minimal() {
	pkgdesc="$pkgdesc (tcmalloc, minimal variant)"

	amove usr/lib/libtcmalloc_minimal.so.*
}

tcmalloc_minimal_debug() {
	pkgdesc="$pkgdesc (tcmalloc, minimal+debug variant)"

	amove usr/lib/libtcmalloc_minimal_debug.so.*
}

tcmalloc_profiler() {
	pkgdesc="$pkgdesc (tcmalloc, profiling variant)"

	amove usr/lib/libtcmalloc_and_profiler.so.*
}

sha512sums="
b30c68b8e6831c2a8d78d632862a77603a6bfb4833c9a40ba7efe43d12f58e9e203079e56510f0512ebb5bf656b1e2d7f0c2bd8f830bdf03d015c506abdb4a2d  gperftools-2.10.80.tar.gz
d4f7cb16985e8e232c0f2e5794adfc06b30d42b4df860fe21954ce79a7537571a439ce3392c652372a44499bb0f3f5ad640d7b7fb1dbf60aa739b841f4723587  failed-tests.patch
bfec285aa83fb8cc1d494bcde50caee3faae8c23e1519c64c43bed05f3c3ccf5ef012bbcfac7a0f4dd41d82d6d2d4589bcb42697ff1e41e20ed548eb5b103ada  pkgconfig.patch
"
